@@layout("/common/_container.html"){
<div class="row">
    <div class="col-md-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h2>Websocket实现向用户发送通知 <small>当前在线人数: ${online!("0")}</small></h2>
            </div>
            <div class="ibox-content">
                <form class="form-horizontal form-label-left" novalidate>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" >消息通知内容<span class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea class="form-control col-md-7 col-xs-12" id="msg" name="msg" required="required" placeholder="请输入消息通知内容" rows="5"></textarea>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" ></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <button type="button" class="btn btn-primary" id="saveBtn"><i class="fa fa-send"> 发送</i></button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    /**
     * websocket消息解析器
     *
     * @type {{online: wesocketMsgResolver.online}}
     */
    var wesocketMsgResolver = {
        online: function (value) {
            value && $(".online").html(value);
        },
        notification: function (value) {
            value && $.notification.show({
                notification: value
            });
        }
    };

    $("#saveBtn").click(function () {
        //提交信息
        var ajax = new $ax(Feng.ctxPath + "/notice/sengAdminMsg", function (data) {
            Feng.pass(data,function () {
                Feng.success("发送成功!");
            });
        }, function (data) {
            Feng.error("发送失败!" + data.msg + "!");
        });
        ajax.set({msg : $("#msg").val()});
        ajax.start();

    });

    $.websocket.open({
        host: appConfig.websocketUrl+"/${shiro.getUser().id!}",
        reconnect: true,
        callback: function (event) {

        }
    });

</script>
@@}
